﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.UI.StaticPartLib
{
    /// <summary>
    /// Interaction logic for PartLabel.xaml
    /// </summary>
    [System.ComponentModel.DisplayName("折叠按钮")]
    [XPartIcon("pack://application:,,,/CPPEI.Coolzon.UI.DataPartLib;component/Images/PartIcons/Null.gif")]
    public partial class PartToggleButton : ControlPart
    {
        [Category("Other")]
        [DisplayName("是否选中")]
        [Description("IsChecked")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "IsChecked", "是否选中")]
        public bool XIsChecked
        {
            get 
            {
                return _XIsChecked;
            }
            set
            {
                _XIsChecked = value;
                Refresh();
            }
        }

        private bool _XIsChecked;

        protected override bool OnReceiveMouseEvent(MouseEventType eventType, Point point)
        {
            if(eventType.Name == MouseEventType.MouseLeftDown.Name)
            {
                XIsChecked = !XIsChecked;
                this.InvokeScriptEvent(PartContext.ScriptEngine,
                    "OnCheckChanged",
                    this.GetScriptObj(),
                    XIsChecked);
                return true;
            }
            return false;
        }
    }
}
